package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.domain.Room;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.WhitelistSettingService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.ManagerService;
import com.example.mybatisplus.model.domain.Manager;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-07-17
 * @version v1.0
 */
@RestController
@RequestMapping("/api/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @PostMapping("login")
    public JsonResponse login(@RequestBody Manager manager){
        Manager user =managerService.login(manager);
        return JsonResponse.success(user);
    }

    @PostMapping("change")
    public JsonResponse change(@RequestBody Manager manager){
        Manager user =managerService.change(manager);
        return JsonResponse.success(user);
    }

    @GetMapping("logout")
    public JsonResponse logout(){
        SessionUtils.clearCurUser();
        return JsonResponse.success(true);
    }
    @GetMapping("pageList")
    public JsonResponse pageList(Manager manager, PageDTO dto){
        // 控制层功能 调用接口 返回结果
        Page<Manager> page = managerService.pageList(manager,dto);
        return JsonResponse.success(page);

    }
    @PostMapping("editSystem")
    public JsonResponse editSystem(@RequestBody Manager manager){
        boolean b=managerService.updateById(manager);
        return JsonResponse.success(b);

    }

    @PostMapping("addSystem")
    public JsonResponse addSystem(@RequestBody Manager manager){
        boolean b = managerService.save(manager); // 或者根据具体情况调用其他适合的方法进行保存操作
        return JsonResponse.success(b); // 返回操作是否成功的 JSON 响应
    }

}

